<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="s" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="f" uri="http://www.sctv.com/tags/form"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags"%>
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags"%>
<!DOCTYPE html>
<html>
<head>
<jsp:include page="/WEB-INF/views/head.jsp"/>
<script type="text/javascript">
$(function() {
	
	$("#sortHead").headSort();
});
function confirmDelete() {
	return confirm("<s:message code='confirmDelete'/>");
}
function optSingle(opt) {
	if(Cms.checkeds("ids")==0) {
		alert("<s:message code='pleaseSelectRecord'/>");
		return false;
	}
	if(Cms.checkeds("ids")>1) {
		alert("<s:message code='pleaseSelectOne'/>");
		return false;
	}
	var id = $("input[name='ids']:checkbox:checked").val();
	location.href=$(opt+id).attr("href");
}
function optDelete(form) {
	if(Cms.checkeds("ids")==0) {
		alert("<s:message code='pleaseSelectRecord'/>");
		return false;
	}
	if(!confirmDelete()) {
		return false;
	}
	form.action='delete.do';
	form.submit();
	return true;
}
function  updatePriority(specId) {
  if (specId == '' || specId == null) {
    return false;
  }
  var priority = $("#" + specId).val();
  var r = new RegExp("^(\\d|[1-9]\\d|100)$");　　//0-100整数
  if (!r.test(priority)) {
    alert("请输入数字0~100（整数）！");
    return false;
  }
  var data = {};
  data.specId = specId;
  data.priority = priority;
  var url = CMSCP + '/core/special/updatePriority.do';
  $.ajax({
    type: "POST",
    url: url,
    dataType: "json",
    data: data,
    async: false,
    success: function (msg) {
      if (msg.msg == 'success') {
        alert('修改成功！');
      } else {
        alert('参数错误，请刷新重试！');
      }

    },
    error: function (msg) {
      alert("系统异常！");
    }
  });
}
function jpushNodeInfoView(specId,title) {
  var data = {};
  data.specId = specId;
  data.title = title;
  var obj = ajaxView("/cmscp/core/special/jpushSpec.do", "json", data);
  if(obj.msg=='data_error'){
    obj.msg="数据状态发生变化（未发布、子专题不能推送），请刷新重试！";
  }
  alert("推送：" + obj.msg);
}

function ajaxView(mothe, datatype, data) {
  var obj;
  var strurl = window.location.host;
  $.ajax({
    type: "POST",
    url: "http://" + strurl + mothe,
    dataType: datatype,
    data: data,
    async: false,
    success: function (msg) {
      obj = msg;
    },
    error: function (msg) {
    }
  });
  return obj;
}
</script>
</head>
<body class="skin-blue content-body" id="load">
<jsp:include page="/WEB-INF/views/commons/show_message.jsp"/>
<div class="content-header">
	<h1><s:message code="special.management"/> - <s:message code="list"/> <small>(<s:message code="totalElements" arguments="${pagedList.totalElements}"/>)</small></h1>
</div>
<div class="content">
	<div class="box box-primary">
		<div class="box-body table-responsive">
			<form class="form-inline ls-search" action="list.do" method="get">
                <f:hidden name="parentId" value="${parentId}"/>
				<div class="form-group">
				  <label><s:message code="special.title"/></label>
				  <f:text class="form-control input-sm" name="search_CONTAIN_title" value="${search_CONTAIN_title[0]}" style="width:180px;"/>
				</div>
				<div class="form-group">
				  <label><s:message code="beginTime"/></label>
				  <f:text class="form-control input-sm" name="search_GTE_creationDate_Date" value="${search_GTE_creationDate_Date[0]}" onclick="WdatePicker({dateFmt:'yyyy-MM-dd'});"  style="width:120px;"/>
				</div>
				<div class="form-group">
				  <label><s:message code="endTime"/></label>
				  <f:text class="form-control input-sm" name="search_LTE_creationDate_Date" value="${search_LTE_creationDate_Date[0]}" onclick="WdatePicker({dateFmt:'yyyy-MM-dd'});"  style="width:120px;"/>
				</div>
				<div class="form-group">
				  <label><s:message code="special.category"/></label>
			  	<select class="form-control input-sm" input-sm name="search_EQ_category.id">
			  		<option value=""><s:message code="allSelect"/></option>
			  		<f:options items="${categoryList}" itemValue="id" itemLabel="name" selected="${requestScope['search_EQ_category.id'][0]}"/>
			  	</select>
				</div>
				<%--<div class="form-group">--%>
				  <%--<label>专题级别</label>--%>
			  	<%--<select class="form-control input-sm" name="search_EQ_level">--%>
			  		<%--<option value=""><s:message code="allSelect"/></option>--%>
			  		<%--<f:option value="0" selected="${search_EQ_level[0]}">父专题</f:option>--%>
			  		<%--<f:option value="1" selected="${search_EQ_level[0]}">子专题</f:option>--%>
			  	<%--</select>--%>
				<%--</div>		  --%>
			  <button class="btn btn-default btn-sm" type="submit"><s:message code="search"/></button>
                <c:if test="${not empty parentId}">
                    <button class="btn btn-default" onclick="location.href='list.do?${searchstring}';" type="button">返回</button>
                </c:if>
			</form>
			<form action="batch_update.do" method="post">
                <f:hidden name="parentId" value="${parentId}"/>
				<tags:search_params/>
				<div class="btn-toolbar ls-btn-bar">
                    <div class="btn-group">
                        <shiro:hasPermission name="core:speciallist:generationSpec">
                            <button class="btn btn-default" type="button" onclick="$('#load').showLoading();location.href='/cmscp/core/generation/generationDataByNode.do?returnUrl=/cmscp/core/special/list&queryNodeId=${queryNodeId}';">生成</button>
                        </shiro:hasPermission>
                    </div>
					<div class="btn-group">
						<shiro:hasPermission name="core:special:create">
						<button class="btn btn-default" type="button" onclick="location.href='create.do?${searchstring}';"><s:message code="create"/></button>
						</shiro:hasPermission>
					</div>
					<div class="btn-group">
						<shiro:hasPermission name="core:special:copy">
						<button class="btn btn-default" type="button" onclick="return optSingle('#copy_opt_');"><s:message code="copy"/></button>
						</shiro:hasPermission>	
						<shiro:hasPermission name="core:special:edit">
						<button class="btn btn-default" type="button" onclick="return optSingle('#edit_opt_');"><s:message code="edit"/></button>
						</shiro:hasPermission>
					</div>
					<%--<div class="btn-group">--%>
						<%--<shiro:hasPermission name="core:special:delete">--%>
						<%--<button class="btn btn-default" type="button" onclick="return optDelete(this.form);"><s:message code="delete"/></button>--%>
						<%--</shiro:hasPermission>--%>
					<%--</div>--%>
                    <%------------------------------ [ 推送弹窗 ] -------------------------------%>
                    <div id="dialog-message" title="推送信息" style="display: none">
                        <p>标题</p>
                        <textarea  id="sendViewTitle" value="" rows="5" cols="30"></textarea>
                    </div>
                    <%--<input type="button" value="Show Dialog" onclick="showDialog();" />--%>
                    <script>
                      function showDialog(specId,title) {
                        $("#dialog-message").dialog({
                          height: 300,
                          width: 400,
                          // 模态开启
                          modal: true,
                          // 是否可拖拽
                          draggable: false,
                          // 最小宽度
                          minWidth: 300,
                          buttons: {
                            "推送信息": function() {
                              var value =  $("#sendViewTitle").val();
                              jpushNodeInfoView(specId,value);
                              $(this).dialog("close");
                            },
                            "取消": function() {

                              $(this).dialog("close");
                            }
                          }
                        });
                         $("#sendViewTitle").val(title);
                      }

                    </script>
				</div>
				<table id="pagedTable" class="table table-condensed table-bordered table-hover ls-tb">
				  <thead id="sortHead" pagesort="<c:out value='${page_sort[0]}' />" pagedir="${page_sort_dir[0]}" pageurl="list.do?page_sort={0}&page_sort_dir={1}&${searchstringnosort}">
				  <tr class="ls_table_th">
				    <th width="25"><input type="checkbox" onclick="Cms.check('ids',this.checked);"/></th>
				    <th width="30" class="ls-th-sort"><span class="ls-sort" pagesort="id">ID</span></th>
				    <th class="ls-th-sort"><span class="ls-sort" pagesort="category.name"><s:message code="special.category"/></span></th>
				    <th class="ls-th-sort"><span class="ls-sort" pagesort="model.name"><s:message code="special.model"/></span></th>
				    <th class="ls-th-sort"><span class="ls-sort" pagesort="title"><s:message code="special.title"/></span></th>
				    <%--<th class="ls-th-sort"><span class="ls-sort" pagesort="views"><s:message code="special.views"/></span></th>--%>
                    <th class="ls-th-sort"><span class="ls-sort" pagesort="priority">优先级</span><span style="color: red"><br/>(0-100整数，数值大，优先级高)</span></th>
				    <%--<th class="ls-th-sort"><span class="ls-sort" pagesort="recommend"><s:message code="special.recommend"/></span></th>--%>
                    <th>专题级别</th>
                    <th width="200">发布状态</th>
				    <th class="ls-th-sort"><span class="ls-sort" pagesort="creationDate"><s:message code="special.creationDate"/></span></th>
                    <th width="250"><s:message code="operate"/></th>
				  </tr>
				  </thead>
				  <tbody>
				  <c:forEach var="bean" varStatus="status" items="${pagedList.content}">
				  <tr>
				    <td><input type="checkbox" name="ids" value="${bean.id}"/></td>
				    <td><c:out value="${bean.id}"/></td>
				    <td><c:out value="${bean.category.name}"/></td>
				    <td><c:out value="${bean.model.name}"/></td>
				    <td><c:out value="${bean.title}"/></td>
				    <%--<td><c:out value="${bean.views}"/></td>--%>
                    <td align="right" style="text-align: center"><f:text class="form-control input-sm" name="priority" id="${bean.id}" style="    width: 60px;    display: -webkit-inline-box;" maxlength="9" AUTOCOMPLETE="OFF" value="${bean.priority}"/>
                          <button class="btn btn-default" type="button" onclick="updatePriority(${bean.id})">保存</button>
                    </td>
				    <td>
                        <c:choose><c:when test="${bean.level eq  0}">
                            <span>父专题</span>
                            <span><a href="list.do?parentId=${bean.id}">子专题(${fn:length(bean.children)}条)</a></span>
                        </c:when>
                        <c:otherwise><span>子专题</span></c:otherwise></c:choose>
                    </td>
                    <td>
                        <c:if test="${bean.level eq 0}">
                        <c:choose>
                        <c:when test="${bean.publish eq  0}"><span style="color: red">已发布</span></c:when>
                        <c:otherwise><span>未发布</span></c:otherwise></c:choose>
                            <shiro:hasPermission name="core:special:updatePublish">
                                <button class="btn btn-default" type="button" onclick="$('#load').showLoading();location.href='updatePublish.do?specId=${bean.id}';">切换状态</button>
                            </shiro:hasPermission>
                            <shiro:hasPermission name="core:special:generationSpec">
                                <button class="btn btn-default" type="button" onclick="$('#load').showLoading();location.href='generationSpec.do?specId=${bean.id}';">生成</button>
                            </shiro:hasPermission>
                        </c:if>

                    </td>
				    <td align="center"><fmt:formatDate value="${bean.creationDate}" pattern="yyyy-MM-dd HH:mm:ss"/></td>
                  <td align="center">
                      <shiro:hasPermission name="core:special:jpushSpec">
                      <c:if test="${bean.level eq  0 && bean.publish eq 0 }">
                          <a href='javascript:void(0)' onclick=" showDialog(${bean.id},'${bean.title}')"
                          >推送</a>
                      </c:if>
                      </shiro:hasPermission>
                      <shiro:hasPermission name="core:special:copy">
                          <a id="copy_opt_${bean.id}" href="create.do?id=${bean.id}&${searchstring}" class="ls-opt"><s:message code="copy"/></a>
                      </shiro:hasPermission>
                      <shiro:hasPermission name="core:special:edit">
                          <a id="edit_opt_${bean.id}" href="edit.do?parentId=${parentId}&id=${bean.id}&position=${pagedList.number*pagedList.size+status.index}&${searchstring}" class="ls-opt"><s:message code="edit"/></a>
                      </shiro:hasPermission>
                      <shiro:hasPermission name="core:info:list">
                          <c:url var="infoListUrl" value="../info/list.do">
                              <c:param name="search_EQ_JinfoSpecials.Jspecial.title" value="${bean.title}"/>
                          </c:url>
                          <a id="infoList_opt_${bean.id}" href="${infoListUrl}" class="ls-opt"><s:message code="special.infoList"/></a>
                      </shiro:hasPermission>
                          <%--<shiro:hasPermission name="core:special:delete">--%>
                          <%--<a href="delete.do?ids=${bean.id}&${searchstring}" onclick="return confirmDelete();" class="ls-opt"><s:message code="delete"/></a>--%>
                          <%--</shiro:hasPermission>--%>
                      <shiro:hasPermission name="core:site:delete01">
                          <c:choose>
                              <c:when test="${bean.id==1}">
                                  <a class="ls-opt-disabled"><s:message code="recycle"/></a>
                              </c:when>
                              <c:otherwise>
                                  <a href="updateDelStatus.do?parentId=${parentId}&ids=${bean.id}&${searchstring}" onclick="return confirmDelete();" class="ls-opt"><s:message code="recycle"/></a>
                              </c:otherwise>
                          </c:choose>
                      </shiro:hasPermission>
                  </td>
				  </tr>
				  </c:forEach>
				  </tbody>
				</table>
				<c:if test="${fn:length(pagedList.content) le 0}">
				<div class="ls-norecord"><s:message code="recordNotFound"/></div>
				</c:if>
			</form>
			<form action="list.do" method="get" class="ls-page">
            <f:hidden name="parentId" value="${parentId}"/>
            <tags:search_params excludePage="true"/>
            <tags:pagination pagedList="${pagedList}"/>
        </form>
		</div>
	</div>
</div>
			

</body>
</html>